// $ANTLR 3.1.3 Mar 17, 2009 19:23:44 CalculatorWalker.g 2010-01-30 20:46:29

package org.concepts.java.antlr.calculator;


import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

public class CalculatorWalker extends TreeParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "INT", "PLS", "MIN", "MUL", "DIV", "LPAREN", "RPAREN", "WHITESPACE"
    };
    public static final int RPAREN=10;
    public static final int WHITESPACE=11;
    public static final int PLS=5;
    public static final int INT=4;
    public static final int MIN=6;
    public static final int DIV=8;
    public static final int EOF=-1;
    public static final int MUL=7;
    public static final int LPAREN=9;

    // delegates
    // delegators


        public CalculatorWalker(TreeNodeStream input) {
            this(input, new RecognizerSharedState());
        }
        public CalculatorWalker(TreeNodeStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        

    public String[] getTokenNames() { return CalculatorWalker.tokenNames; }
    public String getGrammarFileName() { return "CalculatorWalker.g"; }



    // $ANTLR start "expr"
    // CalculatorWalker.g:12:1: expr returns [int result = 0] : ( ^( PLS first= expr second= expr ) | ^( MIN first= expr second= expr ) | ^( MUL first= expr second= expr ) | ^( DIV first= expr second= expr ) | INT );
    public final int expr() throws RecognitionException {
        int result =  0;

        CommonTree INT1=null;
        int first = 0;

        int second = 0;


        try {
            // CalculatorWalker.g:13:3: ( ^( PLS first= expr second= expr ) | ^( MIN first= expr second= expr ) | ^( MUL first= expr second= expr ) | ^( DIV first= expr second= expr ) | INT )
            int alt1=5;
            switch ( input.LA(1) ) {
            case PLS:
                {
                alt1=1;
                }
                break;
            case MIN:
                {
                alt1=2;
                }
                break;
            case MUL:
                {
                alt1=3;
                }
                break;
            case DIV:
                {
                alt1=4;
                }
                break;
            case INT:
                {
                alt1=5;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 1, 0, input);

                throw nvae;
            }

            switch (alt1) {
                case 1 :
                    // CalculatorWalker.g:13:4: ^( PLS first= expr second= expr )
                    {
                    match(input,PLS,FOLLOW_PLS_in_expr46); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr50);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr54);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                        result = first + second; 
                      

                    }
                    break;
                case 2 :
                    // CalculatorWalker.g:18:3: ^( MIN first= expr second= expr )
                    {
                    match(input,MIN,FOLLOW_MIN_in_expr68); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr72);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr76);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                        result = first - second; 
                      

                    }
                    break;
                case 3 :
                    // CalculatorWalker.g:23:3: ^( MUL first= expr second= expr )
                    {
                    match(input,MUL,FOLLOW_MUL_in_expr90); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr94);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr98);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                        result = first  * second; 
                      

                    }
                    break;
                case 4 :
                    // CalculatorWalker.g:28:3: ^( DIV first= expr second= expr )
                    {
                    match(input,DIV,FOLLOW_DIV_in_expr112); 

                    match(input, Token.DOWN, null); 
                    pushFollow(FOLLOW_expr_in_expr116);
                    first=expr();

                    state._fsp--;

                    pushFollow(FOLLOW_expr_in_expr120);
                    second=expr();

                    state._fsp--;


                    match(input, Token.UP, null); 

                        result = first / second; 
                      

                    }
                    break;
                case 5 :
                    // CalculatorWalker.g:33:3: INT
                    {
                    INT1=(CommonTree)match(input,INT,FOLLOW_INT_in_expr133); 

                        result = Integer.parseInt((INT1!=null?INT1.getText():null));
                      

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return result;
    }
    // $ANTLR end "expr"

    // Delegated rules


 

    public static final BitSet FOLLOW_PLS_in_expr46 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr50 = new BitSet(new long[]{0x00000000000001F0L});
    public static final BitSet FOLLOW_expr_in_expr54 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_MIN_in_expr68 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr72 = new BitSet(new long[]{0x00000000000001F0L});
    public static final BitSet FOLLOW_expr_in_expr76 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_MUL_in_expr90 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr94 = new BitSet(new long[]{0x00000000000001F0L});
    public static final BitSet FOLLOW_expr_in_expr98 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_DIV_in_expr112 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_expr116 = new BitSet(new long[]{0x00000000000001F0L});
    public static final BitSet FOLLOW_expr_in_expr120 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_INT_in_expr133 = new BitSet(new long[]{0x0000000000000002L});

}